package cn.mumzone.basic.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * Created by qyd on 2017/7/3.
 */

public class ListUtil {

    /**
     *
     * @param list
     * @return
     */
    public static boolean isListEmpty(List list) {
        return (null == list || list.size() == 0);
    }

    /**
     *
     * @param list
     * @return
     */
    public static boolean isListNotEmpty(List list) {
        return !isListEmpty(list);
    }

    /**
     *
     * @param list
     * @return
     */
    public static boolean isArrayNotEmpty(Object[] list) {
        return !isArrayEmpty(list);
    }
    /**
     *
     * @param list
     * @return
     */
    public static boolean isArrayEmpty(Object[] list) {
        return (null == list || list.length == 0);
    }


    public static <T> List<T> deepCopy(List<T> src){
        try {
            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(byteOut);
            out.writeObject(src);

            ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
            ObjectInputStream in = new ObjectInputStream(byteIn);
            @SuppressWarnings("unchecked")
            List<T> dest = (List<T>) in.readObject();
            return dest;
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ArrayList<>();
    }


}
